package com.mapbased.wfw.components;

import java.io.*;

import org.dom4j.*;
import com.mapbased.wfw.*;
import java.util.Map;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2004</p>
 *
 * <p>Company: mapbased.com</p>
 *
 * @author chy_hs(Baily)
 * @version 1.0
 */
public class TemplateComponent
    extends Component
{
    public TemplateComponent()
    {
    }

    protected String template="DefaultComponent";
    /**
     * if more than one template component will generate again,this is error stat
     * but i dont know how to fix
     * @param context RenderContext
     * @param sb StringBuffer
     * @param m Map
     */
    public void renderHeader(RenderContext rc,StringBuffer sb,Map m)
    {
        renderBinding(rc,this.headSegments,sb);

    }

    /**
     * parseXml
     *
     * @param ele Element
     * @todo Implement this com.mapbased.wfw.Component method
     */
    public Element parseXml(Element ele,PageLoader.LoadContext lc)
    {

        String s=ele.attributeValue("template");
        if(s != null)
        {
            this.template=s;
        }

        return ele;
    }

    /**
     * render
     *
     * @param context RenderContext
     * @throws IOException
     * @todo Implement this com.mapbased.wfw.Component method
     */
    public void render(RenderContext context)
        throws IOException
    {
        this.defalutRenderBehavior(context);
    }

    public String excuteTimeBinding(RenderContext ctx)
    {
        Long l=(Long)ctx.getRequestMap().get(Constants.Page_Start_Time);
        if(l != null)
        {
            long ll=System.currentTimeMillis();
            return new StringBuffer().append (ll - l.longValue())
                .append(" ms  At:").append(new java.util.Date(ll))
                .toString();
        }
        return "Not fetch";
    }

    public String currentTimeBinding(RenderContext rc)
    {
        return new java.util.Date(System.currentTimeMillis()).toString();
    }

    public String pagePathBinding(RenderContext ctx)
    {
        return ctx.getPageHandler().getPagePath();
    }

}
